package com.baseframe.system.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baseframe.system.entity.request.BaseNoticeRequest;
import com.baseframe.system.entity.vo.BaseNoticeVO;
import com.baseframe.system.service.BaseNoticeService;
import com.baseframe.tool.result.R;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;


/**
 * 公告管理
 */
@RestController
@RequestMapping("/back/notice")
@AllArgsConstructor
public class BackBaseNoticeController {

    private BaseNoticeService baseNoticeService;

    /**
     * 添加公告
     * @param request
     * @return
     */
    @PostMapping("/add")
    public R<Object> addNotice(@RequestBody BaseNoticeRequest request){


        return baseNoticeService.addNotice(request)?R.success():R.fail();
    }


    /**
     * 分页查询
     * @param page
     * @param request
     * @return
     */
    @GetMapping("/page")
    public R<Page<BaseNoticeVO>> noticePageList(Page<BaseNoticeVO> page, BaseNoticeRequest request){

        return R.data(baseNoticeService.noticePageList(page,request));
    }


    /**
     * 删除公告
     * @param request
     * @return
     */
    @PostMapping("/delete")
    public R<Object> deleteById(@RequestBody BaseNoticeRequest request){
        if (request.getId()==null){
            return R.fail("缺少必要请求参数~");
        }

        return baseNoticeService.deleteById(request.getId())?R.success():R.fail();
    }


}
